﻿using AspNetExpressInformationManageSystem.App_Start;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;

namespace AspNetExpressInformationManageSystem.Models
{
    public class ExpressGoods
    {
        [Key]
        [Display(Name = "编号")]
        public int ID { get; set; }
        [Required]
        [Display(Name = "寄件人")]
        public String SenderName { get; set; }
        [Required]
        [DataType(DataType.PhoneNumber, ErrorMessage = "必须为数字电话号码")]
        [Display(Name = "电话")]
        [StringLength(11, ErrorMessage = "必须为11位或7位数字", MinimumLength = 7)]
        public String SenderTel { get; set; }
        [Required]
        [Display(Name = "地址")]
        public String SenderAddr { get; set; }
        [Required]
        [DataType(DataType.PostalCode)]
        [Display(Name = "邮编")]
        [StringLength(6, ErrorMessage = "邮编必须为6位数字", MinimumLength = 6)]
        public String SenderZipCode { get; set; }
        [Required]
        [Display(Name = "收件人")]
        public String ReceiverName { get; set; }
        [Required]
        [DataType(DataType.PhoneNumber, ErrorMessage = "必须为数字电话号码")]
        [Display(Name = "电话")]
        [StringLength(11, ErrorMessage = "必须为11位或7位数字", MinimumLength = 7)]
        public String ReceiverTel { get; set; }
        [Required]
        [Display(Name = "地址")]
        public String ReceiverAddr { get; set; }
        [Required]
        [DataType(DataType.PostalCode)]
        [Display(Name = "邮编")]
        [StringLength(6, ErrorMessage = "邮编必须为6位数字", MinimumLength = 6)]
        public String ReceiverZipCode { get; set; }
        [Required]
        [Display(Name = "重量")]
        public Int16 Weight { get; set; }
        [Required]
        [Display(Name = "体积")]
        public Int16 Size { get; set; }
        [Required]
        [Display(Name = "费用")]
        public Int16 Cost { get; set; }
        [Display(Name = "日期")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime Date { get; set; }
        [Display(Name = "备注")]
        public String Remark { get; set; }
        [Required]
        [Display(Name = "状态")]
        public String Status { get; set; }
    }

    public class GoodsSearch
    {
        [Display(Name = "编号")]
        public int ID { get; set; }
        [Display(Name = "日期")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime Date { get; set; }
        [Display(Name = "邮编")]
        public String ZipCode { get; set; }
    }

    public class ExpressStorage
    {
        [Key]
        [Display(Name = "编号")]
        public int ID { get; set; }
        [Required]
        [Display(Name = "仓库名")]
        public String Name { get; set; }
        [Required]
        [Display(Name = "地址")]
        public String Addr { get; set; }
        [Required]
        [DataType(DataType.PostalCode)]
        [Display(Name = "邮编")]
        public String ZipCode { get; set; }
        [Required]
        [Display(Name = "类型")]
        public String Type { get; set; }
        [Required]
        [Display(Name = "容量")]
        public int Size { get; set; }
        [Required]
        [Display(Name = "管理员")]
        public String Manager { get; set; }
    }

    public class BaseExpressGoodsStorage
    {
        [Key]
        public int ID { get; set; }
        [Display(Name = "运单")]
        public ExpressGoods ExpressGoods { get; set; }
        [Required]
        [Display(Name = "仓库编号")]
        public int ExpressStorageID { get; set; }
        [Display(Name = "仓库")]
        public ExpressStorage ExpressStorage { get; set; }
        [Required]
        [Display(Name = "操作")]
        public String Action { get; set; }
        [Required]
        [Display(Name = "操作员")]
        public String Operator { get; set; }
        [Required]
        [Display(Name = "日期")]
        [DataType(DataType.DateTime)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime Date { get; set; }
        [Required]
        [Display(Name = "状态")]
        public String Status { get; set; }
    }

    public class ExpressGoodsStorage: BaseExpressGoodsStorage
    {
        public ExpressGoodsStorage() { }
        public ExpressGoodsStorage(BaseExpressGoodsStorage baseExpressGoodsStorage, int expressGoodsID)
        {
            this.ID = baseExpressGoodsStorage.ID;
            this.ExpressGoodsID = expressGoodsID;
            this.ExpressGoods = baseExpressGoodsStorage.ExpressGoods;
            this.ExpressStorageID = baseExpressGoodsStorage.ExpressStorageID;
            this.ExpressStorage = baseExpressGoodsStorage.ExpressStorage;
            this.Action = baseExpressGoodsStorage.Action;
            this.Operator = baseExpressGoodsStorage.Operator;
            this.Date = baseExpressGoodsStorage.Date;
            this.Status = baseExpressGoodsStorage.Status;
        }

        [Required]
        [Display(Name = "运单编号")]
        public int ExpressGoodsID { get; set; }
    }

    public class MultiExpressGoodsStorage: BaseExpressGoodsStorage
    {
        [Required]
        [Display(Name = "运单编号")]
        public String ExpressGoodsID { get; set; }
    }

    public class ExpressVehicle
    {
        [Key]
        public int ID { get; set; }
        [Required]
        [Display(Name = "车牌号")]
        public String PlateNum { get; set; }
        [Required]
        [Display(Name = "载重")]
        public int Load { get; set; }
        [Required]
        [Display(Name = "容量")]
        public int Size { get; set; }
        [Required]
        [Display(Name = "操作员")]
        public String Operator { get; set; }
        [Required]
        [Display(Name = "维护费用")]
        public int Maintenance { get; set; }
        [Required]
        [Display(Name = "油费")]
        public int OilCost { get; set; }
        [Required]
        [Display(Name = "状态")]
        public String Status { get; set; }
    }

    public class ExpressDispatch
    {
        [Key]
        public int ID { get; set; }
        [Required]
        [Display(Name = "运单号")]
        public int ExpressGoodsId { get; set; }
        public ExpressGoods ExpressGoods { get; set; }
        [Required]
        [Display(Name = "车辆")]
        public int ExpressVehicleID { get; set; }
        public ExpressVehicle ExpressVehicle { get; set; }
        [Required]
        [Display(Name = "发货地")]
        public String Fromaddr { get; set; }
        [Required]
        [Display(Name = "收货地")]
        public String Toaddr { get; set; }
        [Required]
        [Display(Name = "距离")]
        public int Distance { get; set; }
        [Display(Name = "日期")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime Date { get; set; }
    }


    public class ExpressAnalysis
    {
        [Key]
        public int ID { get; set; }
        [Required]
        [DataType(DataType.Date)]
        [Display(Name = "日期")]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime Date { get; set; }
        [Required]
        [Display(Name = "运单总额")]
        public int GoodsCash { get; set; }
        [Required]
        [Display(Name = "运输油费总额")]
        public int VehicleOilCost { get; set; }
        [Required]
        [Display(Name = "车辆维护总额")]
        public int VehicleMaintenance { get; set; }
        [Required]
        [Display(Name = "工资总额")]
        public int Salary { get; set; }
    }

    public class ExpressDbContext: DbContext
    {
        public ExpressDbContext(): base("DefaultConnection")
        {
            Database.SetInitializer<ExpressDbContext>(new ExpressDbInitializer());
        }

        public DbSet<ExpressGoods> ExpressGoods { get; set; }
        public DbSet<ExpressStorage> ExpressStorage { get; set; }
        public DbSet<ExpressGoodsStorage> ExpressGoodsStorage { get; set; }
        public DbSet<ExpressVehicle> ExpressVehicles { get; set; }
        public DbSet<ExpressDispatch> ExpressDispatches { get; set; }

        public System.Data.Entity.DbSet<AspNetExpressInformationManageSystem.Models.ExpressAnalysis> ExpressAnalysis { get; set; }
    }
}
